package com.shwread.android.qysw.activity;

import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.shwread.android.qysw10000227.R;


/**
 * @author Administrator
 * 查询聊天界面
 *
 */
public class NewInteractionCenterQueryChatActivity
        extends
        BaseSimpleActivity
        implements
        OnClickListener
{
	
	private EditText  query_et;
	private ImageView query_clear;
	private Button    query_btn;
	private ListView  query_lv;
	private String[]  names    = new String[] {
	        "王大锤",
	        "王尼玛"
	                           };
	private String[]  times    = new String[] {
	        "12:12",
	        "12:56"
	                           };
	private String[]  contents = new String[] {
	        "大四大大三大大飒飒的四大四大四大四大的实施",
	        "打死打死打死打电话建设上电视上谁打我电话发就和就后悔就疏忽或好 后加好好好"
	                           };
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.new_interaction_query_chat_record);
		query_et = (EditText) findViewById(R.id.new_interaction_query_et);
		query_clear = (ImageView) findViewById(R.id.new_interaction_query_clear_iv);
		query_btn = (Button) findViewById(R.id.new_i_query_btn);
		query_lv = (ListView) findViewById(R.id.new_interaction_query_listview);
		
		
		query_et.addTextChangedListener(new EditChangedListener());
		query_clear.setOnClickListener(this);
		query_btn.setOnClickListener(this);
		MyAdapter adapter = new MyAdapter(this);
		query_lv.setAdapter(adapter);
		
	}
	
	@Override
	public void onClick(View view) {
		switch (view.getId()) {
			case R.id.new_interaction_query_clear_iv://清除文本
				query_et.setText("");
				query_clear.setVisibility(View.GONE);
				break;
			case R.id.new_i_query_btn://查询

				break;

			default:
				break;
		}
	}
	
	class EditChangedListener
	        implements
	        TextWatcher
	{

		@Override
		public void afterTextChanged(Editable arg0) {

		}

		@Override
		public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {

		}

		@Override
		public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
			query_clear.setVisibility(View.VISIBLE);
		}

	}
	
	class MyAdapter
	        extends
	        BaseAdapter
	{
		private Context context;

		public MyAdapter(Context context) {
			this.context = context;
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return names.length;
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return names[position];
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ViewHolder holder = null;
			if (convertView == null)
			{
				convertView = LayoutInflater.from(context).inflate(R.layout.new_interaction_query_lv_item, null);
				holder = new ViewHolder();
				holder.headportrait_iv = (ImageView) convertView.findViewById(R.id.new_i_query_lv_headportrait);
				holder.name_tv = (TextView) convertView.findViewById(R.id.new_i_query_lv_name);
				holder.time_tv = (TextView) convertView.findViewById(R.id.new_i_query_lv_time);
				holder.content_tv = (TextView) convertView.findViewById(R.id.new_i_query_lv_content);
				convertView.setTag(holder);
			}
			else
			{
				holder = (ViewHolder) convertView.getTag();
			}
			//  holder.headportrait_iv.setBackground(background);
			holder.name_tv.setText(names[position]);
			holder.time_tv.setText(times[position]);
			holder.content_tv.setText(contents[position]);
			return convertView;
		}

	}
	
	class ViewHolder
	{
		public ImageView headportrait_iv;
		public TextView         name_tv, time_tv, content_tv;
	}
	
}
